﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiiGeeDotNet.filter
{
  public class IdleStateFilter : Filter
  {

    private double m_sensivity;

    /**
     * Since an acceleration sensor usually provides information even
     * if it doesn't move, this filter removes the data if it's in the
     * idle state.
     */
    public IdleStateFilter()
      : base()
    {
      this.m_sensivity = 0.1;
    }

    public override double[] FilterAlgorithm(double[] vector)
    {
      // calculate values needed for filtering:
      // absolute value
      double absvalue = Math.Sqrt((vector[0] * vector[0]) +
          (vector[1] * vector[1]) + (vector[2] * vector[2]));

      // filter formulaes and return values
      if (absvalue > 1 + this.m_sensivity ||
         absvalue < 1 - this.m_sensivity)
      {
        return vector;
      }
      else
      {
        return null;
      }
    }

    /// <summary>
    /// Defines the absolute value when the wiimote should react to acceleration.
    /// This is a parameter for the first of the two filters: idle state
    /// filter. For example: sensivity=0.2 makes the wiimote react to acceleration
    /// where the absolute value is equal or greater than 1.2g. The default value 0.1
    /// should work well. Only change if you are sure what you're doing.
    /// </summary>
    public double Sensitivity
    {
      get { return m_sensivity; }
      set { m_sensivity = value; }
    }


  }
}
